Repository navigation
SoundWire: fix pm_runtime usage - #2530
Conversation
|
@fredoh9 is there a way you can start a manual daily test on this PR before the week-end? |
Yes there is a easy way to run daily test. I will trigger this and let you know. |
3fb0e8d to
da41eac
Compare
|
@bardliao I found additional problems... The use of regcache in the resume routine was probably broken, and the master device didn't seem to have the right pm_runtime settings either. With these changes pm_runtime seems to be fine, but somehow the second system suspend with rtcwake is fatal -> cannot resume. I must have missed something. Not sure why the first suspend-resume works. @ranj063 does this ring a bell? I never suspected we had so many issues in the code... |
| ret = pm_runtime_get_sync(&slave->dev); | ||
| if (ret < 0 && ret != -EACCES) { | ||
| pm_runtime_put_noidle(slave->bus->dev); | ||
| pm_runtime_put_noidle(&slave->dev); |
There was a problem hiding this comment.
@plbossart I don't know if it is a right change. As you said in #2521, there is a dead lock between regcache_cache_only and regmap_read. The codec driver's logic is that it doesn't expect any IO access in suspend even the register is volatile. And that's why we set cache only in suspend and sync cache in resume. We will get XX when we try to read a register which is unavailable and it is a normal behavior of regmap. Codec driver should resume codec device before regmap_read if it want to read a volatile register in suspend.
There was a problem hiding this comment.
it's absolutely the right change. We should NOT deal with the parent when playing with the codec. That is a recipe for not waiting for the resume to complete.
I agree there is a conceptual issue with regmap but hiding it by changing the power state at a higher level is completely wrong. We've done this before and it was really bad.
There was a problem hiding this comment.
Hmm, I don't have the full soundwire context, but I agree this seems like the right thing and is aligned with HDA (e.g. in hdac_device.c we do not power up/down the bus, but rather the device).
| pm_runtime_mark_last_busy(&bus->md->dev); | ||
| pm_runtime_set_active(&bus->md->dev); | ||
| pm_runtime_enable(&bus->md->dev); | ||
| pm_runtime_idle(&bus->md->dev); |
There was a problem hiding this comment.
do I understand it correctly, that with this patch the problem, described in the commit message, doesn't occur any more, because in those cases, when rt-PM is trying to activate a child, now the parent isn't yet suspended because of the autosuspend delay?.. If that's correct, it doesn't seem right to me, relying on autosuspend to keep the parent on while we (re-)activate a child?
There was a problem hiding this comment.
no, the point is that we let the parent be part of the pm_runtime flow.
When we activate a child, the parent will be activated by construction. Likewise, when the child is no longer active, the parent will be suspended as well.
This initial pm_runtime_idle is just to make sure the device becomes suspended IF its children are also suspended. Otherwise we've set it as active initially and it remains active forever.
There was a problem hiding this comment.
Sorry, my question wasn't to that pm_runtime_idle() call but to the complete code block, rather to the autosuspend handling. Whether setting parent's autosuspend timeout we make sure it's still active in the beginning of the runtime suspend process?
BTW, in the commit message you probably meant "Force the parent device"
There was a problem hiding this comment.
Sorry @lyakh I don't understand the objection or question.
You can only enter the pm_runtime suspend routine if the device is pm_runtime_active. that's by design. We use the same sequence in Ranjani's probes and audio client patches. It's not new, just the same recipe applied here.
There was a problem hiding this comment.
The commit message says, that this patch fixes the
runtime PM trying to activate child device sdw:3:25d:715:0 but parent (sdw-master-3) is not active
error message by "forcing the parent device to be active and using autosuspend to avoid these warnings." That makes me think, that without this patch the parent has already suspended when the driver is trying to activate the child. And with this patch the parent isn't yet suspended at that time, because it's still in its autosuspend delay?
There was a problem hiding this comment.
For PM runtime, a child can only become active when its parents are also active, and conversely a parent can only suspend when all of its children are suspended.
This sdw-master-N parent is an artificial layer we don't really needed, so we are just making it 'transparent' from the pm_runtime perspective, so that the codec device and the Intel master interface are connected and pm_runtime behaves as expected.
The first part is to make sure the device becomes active initially. If you don't no one will ever request the device to be active, and you get those warnings. By setting it to active, you allow the children to become active as well.
The autosuspend is the dual operation. You allow this device to suspend when no children are active.
There was a problem hiding this comment.
@plbossart so the error message appears not because the parent got suspended but because it wasn't activated to begin with? Got it, thanks!
@plbossart we had similar issues with subsequent system suspend/resume because of imbalances in the sequences for suspend/resume in the past. Do you have the log error for the failure? |
No. the device is stuck on the second suspend and I lose all connections. Hard reboot by pressing the power button is the only way out. Isn't there a way to simulate a suspend/resume at a device level? I am pretty sure I've seen something on this before. |
Not really, Pierre. I had a crude way to do this using a temporary debugfs entry to call the suspend/resume callbacks from userspace. Let me bring up my system in the next couple of hours and I can help debug this. |
|
@ranj063 the issue I had was with rtcwake. When I use the information provided by Ubuntu (https://wiki.ubuntu.com/DebuggingKernelSuspend) and run apt install pm-utils
sync && echo 1 > /sys/power/pm_trace && pm-suspend"then I can suspend-resume as much as I want. Weird. Update: I can reproduce the issue, this happens when I try the 'platform' level on the second test. |
Update2: turns out the first resume never completes, so the second is stuck.... Debugging. |
da41eac to
7ed374e
Compare
| pm_runtime_get_noresume(&slave->dev); | ||
|
|
||
| if (pm_runtime_status_suspended(&slave->dev)) { | ||
| ret = pm_runtime_resume(&slave->dev); |
There was a problem hiding this comment.
@plbossart just out of cuioristy why not just pm_runtime_get_sync() here?
There was a problem hiding this comment.
@ranj063 because we can't call pm_runtime_get_sync() from the resume routine. that leads to a deadlock.
|
@plbossart Similar to |
|
Actually, we don't need |
Sorry, I was wrong. We do need |
@bardliao can you elaborate on the scenario that fails? We do use pm_runtime_get_sync() on an alert, so not sure which path you are referring to. I thought about your suggestion to use no_pm routines from regmap, but we don't really control when regmap will be used. |
When a jack is inserted or removed, the codec will be attached firstly. And the problem happens in sdw_handle_slave_status() Please see the dmesg log when regmap uses sdw_write and sdw_write_no_pm initialization not complete, timed out logno error log
|
|
@bardliao indeed I could reproduce the timeout you mentioned with RT711-sdca (TGL device). I don't get how my tests worked on CML and fail miserably on TGL. That said, with your patch applied instead I can block the device on a capture test, run-all-tests does not complete. Completely stuck, nothing happens in dmesg and I have to power cycle to reboot. Can you try this with the updated branch? Also if you have a branch where all the tests pass, please share it, I am curious as to what happens here. |
|
trace before the device is stuck: |
@plbossart I can reproduce the issue on my side. And I can get the error log after a while later. I think we missed the _no_pm change in regmap-sdw-mbq.c regmap-sdw-mbq.patch--- a/drivers/base/regmap/regmap-sdw-mbq.c
+++ b/drivers/base/regmap/regmap-sdw-mbq.c
diff --git a/drivers/base/regmap/regmap-sdw-mbq.c b/drivers/base/regmap/regmap-s
dw-mbq.c
index 8ce30650b97c..6675c3a4b829 100644
--- a/drivers/base/regmap/regmap-sdw-mbq.c
+++ b/drivers/base/regmap/regmap-sdw-mbq.c
@@ -15,11 +15,11 @@ static int regmap_sdw_mbq_write(void *context, unsigned int
reg, unsigned int va
struct sdw_slave *slave = dev_to_sdw_dev(dev);
int ret;
- ret = sdw_write(slave, SDW_SDCA_MBQ_CTL(reg), (val >> 8) & 0xff);
+ ret = sdw_write_no_pm(slave, SDW_SDCA_MBQ_CTL(reg), (val >> 8) & 0xff);
if (ret < 0)
return ret;
- return sdw_write(slave, reg, val & 0xff);
+ return sdw_write_no_pm(slave, reg, val & 0xff);
}
static int regmap_sdw_mbq_read(void *context, unsigned int reg, unsigned int *val)
@@ -29,11 +29,11 @@ static int regmap_sdw_mbq_read(void *context, unsigned int reg, unsigned int *va
int read0;
int read1;
- read0 = sdw_read(slave, reg);
+ read0 = sdw_read_no_pm(slave, reg);
if (read0 < 0)
return read0;
- read1 = sdw_read(slave, SDW_SDCA_MBQ_CTL(reg));
+ read1 = sdw_read_no_pm(slave, SDW_SDCA_MBQ_CTL(reg));
if (read1 < 0)
return read1;
I don't have it right now. But I am running a full test with this PR plus my regmap_sdw_mbq change. |
I finished the run all test on my TGL rt711-sdca device and found no regression. |
I meant something like For example, if rt711-sdca needs to resume the codec before reading SDW_SCP_SDCA_INTMASK, we can add |
ok, got it now, I thought you meant something inside of the regmap functions. |
ack, I didn't see this warning so missed the root cause. Good catch @bardliao, re-testing now with your fix. |
41644bf to
8da0b83
Compare
kv2019i
left a comment
There was a problem hiding this comment.
A few minor notes, but seems good otherwise. CI results seem fine as well.
The 'master' device acts as a glue layer used during bus initialization only, and it needs to be 'transparent' for pm_runtime management. Its behavior should be that it becomes active when one of its children becomes active, and suspends when all of its children are suspended. In our tests on Intel platforms, we routinely see these sort of warnings on the initial boot: [ 21.447345] rt715 sdw:3:25d:715:0: runtime PM trying to activate child device sdw:3:25d:715:0 but parent (sdw-master-3) is not active This is root-caused to a missing setup to make the device 'active' on probe. Since we don't want the device to remain active forever after the probe, the autosuspend configuration is also enabled at the end of the probe - the device will actually autosuspend only in the case where there are no devices physically attached. In practice, the master device will suspend when all its children are no longer active. Fixes: bd84256 ('soundwire: master: enable pm runtime') Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
When a Slave device is resumed, it may resume the bus and restart the enumeration. During that process, we absolutely don't want to call regular read/write routines which will wait for the resume to complete, otherwise a deadlock occurs. Fixes: 60ee9be ('soundwire: bus: add PM/no-PM versions of read/write functions') Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
When a Slave device is resumed, it may resume the bus and restart the enumeration. During that process, we absolutely don't want to call regular read/write routines which will wait for the resume to complete, otherwise a deadlock occurs. This patch fixes the same problem as the previous one, but is split to make the life of linux-stable maintainers less painful. Fixes: 29d158f ('soundwire: bus: initialize bus clock base and scale registers') Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
There is no need to play with pm_runtime reference counts, if needed the codec drivers are already explicitly resumed. Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
sdw_update_slave_status will be invoked when a codec is attached, and the codec driver will initialize the codec with regmap functions while the codec device is pm_runtime suspended. regmap routines currently rely on regular SoundWire IO functions, which will call pm_runtime_get_sync()/put_autosuspend. This causes a deadlock where the resume routine waits for an initialization complete signal that while the initialization complete can only be reached when the resume completes. The only solution if we allow regmap functions to be used in resume operations as well as during codec initialization is to use _no_pm routines. The duty of making sure the bus is operational needs to be handled above the regmap level. Fixes: 7c22ce6 ('regmap: Add SoundWire bus support') Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Use no_pm versions for write and read. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Intel stress-tests routinely report IO timeouts and invalid power management transitions. Upon further analysis, we seem to be using the wrong devices in pm_runtime calls. Before reading and writing registers, we first need to make sure the Slave is fully resumed. The existing code attempts to do such that, however because of a confusion dating from 2017 and copy/paste, we end-up resuming the parent only instead of resuming the codec device. This can lead to accesses to the Slave registers while the bus is still being configured and the Slave not enumerated, and as a result IO errors occur. This is a classic problem, similar confusions happened for HDaudio between bus and codec device, leading to power management issues. Fix by using the relevant device for all uses of pm_runtime functions. Fixes: 60ee9be ('soundwire: bus: add PM/no-PM versions of read/write functions') Fixes: aa79293 ('soundwire: bus: fix io error when processing alert event') Fixes: 9d715fa ('soundwire: Add IO transfer') Reported-by: Bard Liao <yung-chuan.liao@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
8da0b83 to
1913dcd
Compare
|
@naveen-manohar @sathya-nujella @RDharageswari this PR does not seem to introduce any regressions so far. The additional tests on CML_RVP, TGL_Chromebook and 2 other devices seem fine. |
| ret = sdw_update(slave, SDW_DP0_INTMASK, val, val); | ||
| ret = sdw_update_no_pm(slave, SDW_DP0_INTMASK, val, val); | ||
| if (ret < 0) | ||
| dev_err(slave->bus->dev, |
There was a problem hiding this comment.
@plbossart should we change it to "dev_err(slave->dev,". I see we use slave->dev now
There was a problem hiding this comment.
you're right @RanderWang we should also scan the dev_err/dbg log to see which device is used.
There was a problem hiding this comment.
done, can you recheck @RanderWang and @bardliao ?
There was a problem hiding this comment.
done, can you recheck @RanderWang and @bardliao ?
@plbossart I checked bus.c. I think you didn't miss anything. But I didn't get why do we use bus->dev in sdw_modify_slave_status?
There was a problem hiding this comment.
@bardliao there is only one case with dev_vdbg where we use bus->dev. I wanted to have one bus reference here that shows a bus-level evolution in terms of attachment, so that we can filter it out. It was really more to post-process the results than a functional change.
There was a problem hiding this comment.
@bardliao there is only one case with dev_vdbg where we use bus->dev. I wanted to have one bus reference here that shows a bus-level evolution in terms of attachment, so that we can filter it out. It was really more to post-process the results than a functional change.
ok. got it. Thaks.
The SoundWire bus code confuses bus and Slave device levels for dev_err/dbg logs. That's not impacting functionality but the accuracy of kernel logs. We should only use bus->dev for bus-level operations and handling of Device0. For all other logs where the device number is not zero, we should use &slave->dev to provide more precisions to the user/integrator. Reported-by: Rander Wang <rander.wang@linux.intel.com> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
|
I'll go ahead and merge this, it was reviewed multiple times and we need to start stress testing this code. So far it does not add any regressions, let's see if this actually fixes some of the timeout problems as we saw in early manual tests. |
@bardliao reported a weird behavior in #2521, and suggested a solution in #2526 to make sure resuming a Slave device waits for the bus to be resumed and the enumeration/initialization to complete.
That didn't seem quite right, and after a couple of hours I found major issues leading to timeouts in our solution. Those issues may explain some of the suspend-resume runtime issues we've been seeing randomly for several months now?
There may be other issues hidden, please take the time to look at drivers/soundwire/bus.c and see if you find other problematic cases.